<?php
	//Change By Vyas Ishan 17 May 2013 Task2
	require_once('functions/pageLoad.php');
	//Validation that a user donot come over this page directly unless he is registered
	if (!array_key_exists('user-registered',$_SESSION) ) {
		header("Location: /register-my-business");	
		exit;
	}
	$page_title = 'Subscribe for your business';

	if($_SERVER['REQUEST_METHOD'] == 'POST'){

		$fail = '';
		$fail.= (strlen( trim($_POST['plan_type'])  ) == 0 ) ? '<li>Subscription Plan should be selected</li>' : '';
		if(strlen($fail) > 0){
			$results = '<h1>Subscription error!</h1><p>Please correct the following errors;</p><ul>'.$fail.'</ul>';
		} else {
			// redirect to paypal?
			if ($_POST['plan_type'] != '1' && isset($_POST['plan_type'])){
				header("Location: /registration_payment.php?plan_type=".$_POST['plan_type']);
			} else{
				header("Location: /my-account");
			}
		}
	} else{
		$results = '<h1>Subscribe for your business</h1>';
	}
	$additionalMeta = '';
	include('includes/meta.php');
	include('includes/header.php');
	include('includes/navigation.php');
?>

	<h1>You're one step away from a new stream of work!</h1>
	<?php echo $results; ?>
	<div id="error_div" style="display: none;"></div>

	<form method="post" action="" id="business-subscription" autocomplete="off">
		<div id="registration_form">
			<div id="trade_wrap">
				<h2>Choose your subscription</h2>
				<p>If you have chosen a paid subscription, you will be redirected to our payment provider PayPal for payment.</p>
				<input type="hidden" name="plan_type" id="plan_type" value="" />
				<div class="pricing_plans">

				<?php

					//Change By Vyas Ishan 16 May 2013 Task2
					#$pp_sql = "SELECT id, name, radius, cost, status FROM subscriptions WHERE status = '1' ORDER BY cost";
					//Change By Vyas Ishan 24 May 2013 Task2 added the status field condition
					$pp_sql = "SELECT id, name, radius, cost FROM subscriptions where status = '1' ORDER BY cost ";
					$pp_query=mysql_query( $pp_sql ) or die ("Error in query: $pp_sql . " . mysql_error());

					while($pp_rs=mysql_fetch_assoc($pp_query)){
						echo '<div class="price_plan">
								<h2 class="plan_'.$pp_rs['id'].'">'.$pp_rs['name'].'</h2>
								<ul>
									<li>Unlimited quotations</li>
									<li>Company profile page</li>
									<li>Email alerts</li>
									<li>1000 free SMS alerts</li>
									<li>'.$pp_rs['radius'].' mile quote radius</li>
								</ul>';
						echo ($pp_rs['cost'] > 0) ? '<span class="price">&pound;'.$pp_rs['cost'].' per year</span>' : '<span class="price">FREE</span>' ;
						echo '<a onclick="document.getElementById(\'plan_type\').value = \''.$pp_rs['id'].'\'; document.forms[\'business-subscription\'].submit();"><img src="/images/submit_button.gif" alt="Register" /></a></div>';
					}
					
				?>
				</div>
				</div>
			</div>
	</form>

<?php 
include('includes/footer.php');
?>